#include "config.h"
#include "cicm.cpp"
#include <iostream>

/**
  Encrypt entry point. Executes steps 1 - 6 of the test harness scenario.
  @file encrypt.cpp
  @version 0.2
  @date 2011-03-09
*/
int main() {
  CICM::Status s;

  CICM::CICMRoot           *root = new CICM::CICMRoot();
  CICM::ModuleId            module_id = (char*) V_MODULE_ID;
  CICM::CryptoModule       *crypto_mod;
  CICM::SymKeyManager      *sym_key_manager;
  CICM::KeyId               key_id = (char*) V_KEY_ID;
  CICM::SymKey             *key;
  CICM::ChannelManager     *chan_manager;
  CICM::RemotePort          port = V_PORT_ENCRYPT;
  CICM::SymEncrAlgorithmId  algo = (char*) V_ALGORITHM;
  CICM::Encrypt::Conduit   *conduit;
  CICM::Buffer             *payload = new CICM::Buffer(V_PAYLOAD_LEN, (char*) V_PAYLOAD);

  // Step 1. Retrieve the module with the id {as configured}.
  s = root->get_module_by_id(module_id, &crypto_mod);
  if(S_OK == s) std::cout << "Step 1. Got the module." << std::endl;

  // Step 2. Select the symmetric key manager.
  sym_key_manager = crypto_mod->_get_sym_key_manager();
  std::cout << "Step 2. Got the symmetric key manager." << std::endl;

  // Step 3. Select the symmetric key with the id {as configured}.
  s = sym_key_manager->get_key_by_id(key_id,  &key);
  if(S_OK == s) std::cout << "Step 3. Got the symmetric key." << std::endl;

  // Step 4. Select the channel manager.
  chan_manager = crypto_mod->_get_channel_manager();
  std::cout << "Step 4. Got the channel manager." << std::endl;

  // Step 5. Create an encrypt channel that uses an algorithm {as configured}.
  s = chan_manager->create_encrypt_conduit(port, key, algo, &conduit);
  if(S_OK == s) std::cout << "Step 5. Got the conduit." << std::endl;

  // Step 6. Use the channel to encrypt and send a payload {as configured}.
  s = conduit->encrypt(payload);
  if(S_OK == s) std::cout << "Step 6. Encrypted the payload." << std::endl;

  std::cout << "DONE - Encrypt" << std::endl;

  return 0;
}
